﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Web.Mvc.JQueryValidation
{
	public class MaxLengthAttribute : ValidatorAttribute
	{
		private uint maxLength;

		public override string JQueryRule
		{
			get
			{
				return "maxlength: " + maxLength;
			}
		}

		public override string JQueryRuleErrorMessage
		{
			get
			{
				return "maxlength: \"" + JQueryErrorMessage + "\"";
			}
		}

		public override bool Validate(string value)
		{
			return value == null || (value != null && value.Length <= maxLength);
		}

		public MaxLengthAttribute(string fieldName, uint maxLength)
			: base(String.Empty, fieldName)
		{
			this.maxLength = maxLength;
		}

		public MaxLengthAttribute(string formID, string fieldName, uint maxLength)
			: base(formID, fieldName)
		{
			this.maxLength = maxLength;
		}
	}
}